package org.giovanolli.mumi.entities;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * The Class Region.
 */
@Entity
@Table(name = "region")
public class Region extends IdentificableEntity {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 4572690550961368743L;

	/** The name. */
	@Column(name = "name", unique = true)
	private String name;

	/** The cities. */
	@OneToMany(cascade = CascadeType.ALL)
	@JoinColumn(name = "region_id")
	private List<City> cities;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.giovanolli.mumi.entities.IdentificableEntity#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Region other = (Region) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	/**
	 * Gets the cities.
	 * 
	 * @return the cities
	 */
	public List<City> getCities() {
		return cities;
	}

	/**
	 * Gets the name.
	 * 
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.giovanolli.mumi.entities.IdentificableEntity#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cities == null) ? 0 : cities.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	/**
	 * Sets the cities.
	 * 
	 * @param cities
	 *            the new cities
	 */
	public void setCities(List<City> cities) {
		this.cities = cities;
	}

	/**
	 * Sets the name.
	 * 
	 * @param name
	 *            the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.giovanolli.mumi.entities.IdentificableEntity#toString()
	 */
	@Override
	public String toString() {
		return "Region [name=" + name + ", toString()=" + super.toString() + "]";
	}

}
